package cloud.server1;

import java.net.InetSocketAddress;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.netflix.feign.EnableFeignClients;

import cloud.server1.netty.server.NettyServer;
import io.netty.channel.ChannelFuture;

@SpringBootApplication
@EnableDiscoveryClient
@EnableFeignClients
public class CloudApp1 implements CommandLineRunner 
{
    @Autowired
    private NettyServer socketServer;
	/**
	 * 使用整合Spring boot框架启动服务，并调用其他两个服务server1和server2
	 * @param args
	 */
		public static void main(String[] args) {
			SpringApplication.run(CloudApp1.class, args);
			System.out.println("===============================================================================");
			System.out.println("============= CloudApp1 Started ON SpringBoot Success=============");
			System.out.println("===============================================================================");
		}

		@Override
	    public void run(String... strings) {
	        ChannelFuture future = socketServer.run();
	        Runtime.getRuntime().addShutdownHook(new Thread(){
	            @Override
	            public void run() {
	                socketServer.destroy();
	            }
	        });
	        future.channel().closeFuture().syncUninterruptibly();
	    }
}
